#ifndef ZREMOCON_H
#define ZREMOCON_H

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

#include <qpe/config.h>
#include <qwidget.h>
#include <qpoint.h>

#include <KeyBindManager.h>

#define APP_NAME	"ZRemocon"

class QTabBar;
class QWidgetStack;
class QKeyEvent;
class QCloseEvent;
class QResizeEvent;

class MouseWidget;
class MouseDragWidget;
class ConfigWidget;
class RemoconWidget;
class KeyBindWidget;

class ZRemocon: public QWidget
{
	Q_OBJECT
	
public:
	ZRemocon(QWidget *parent = NULL);
/*
	virtual ~ZRemocon();
*/

protected:
	void closeEvent(QCloseEvent *);
	void resizeEvent(QResizeEvent *);
	void keyPressEvent(QKeyEvent *);
	void keyReleaseEvent(QKeyEvent *);

protected slots:
	void closeApplication();
	void rotateScreen();
	void enableKeyHelper();
	void disableKeyHelper();
	void turnOffDisplay();

private:
/*
	typedef enum
	{
		None, ViewStyle, InputStyle,
	} ScreenOrientation;
	
	char _screenOrientation;
*/
	
	Config config;
	
	bool closeAccepted;
	
	int _socket;
	struct sockaddr_in _address;
	
	QTabBar *tabBar;
	QWidgetStack *view;
	
	MouseWidget *mouseWidget;
	MouseDragWidget *mouseDragWidget;
	ConfigWidget *configWidget;
	RemoconWidget *remoconWidget;
	KeyBindWidget *keyBindWidget;
	
	int prevWidgetIndex;
	
	enum
	{
		Widget_MouseWidget,
		Widget_MouseDragWidget,
		Widget_RemoconWidget,
		Widget_ConfigWidget,
		Widget_KeyBindWidget,
	};
	
	KeyBindManager keyBindManager;

private slots:
	void sendKeyPress(unsigned char);
	void sendKeyRelease(unsigned char);
	void sendMouseMoveAbsolute(unsigned short, unsigned short);
	void sendMouseMoveRelative(signed char, signed char);
	void sendMouseLeftButtonClick();
	void sendMouseLeftButtonPress();
	void sendMouseLeftButtonRelease();
	void sendMouseRightButtonClick();
	void sendMouseRightButtonPress();
	void sendMouseRightButtonRelease();
	
	void updateView(int);
	
	void resetSocket();
};

#endif	// ZREMOCON_H
